package com.dcl.spride;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;

public class Info {
	Bean bean = null;
	String name;
	String pass;
	String url;

	Info() {

	}

	public Bean getBean() {
		return bean;
	}

	public void setBean(Bean bean) {
		this.bean = bean;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getInfo() {
		PrintStream out = null;
		try {
			out = new PrintStream(new BufferedOutputStream(
					new FileOutputStream("./error.out")));
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.setErr(out);
		name = bean.getName();
		pass = bean.getPass();
		url = bean.getUrl();
		HttpClient client = new HttpClient();
		GetMethod getmethod = new GetMethod(url);
		getmethod.setRequestHeader("Connection", "close");
		String namepass = name + ":" + pass;
		String show = new String(Base64.encode(namepass.getBytes()));
		getmethod.addRequestHeader("Authorization", "Basic " + show);
		int status = 0;
		try {
			status = client.executeMethod(getmethod);
		} catch (HttpException e) {
		} catch (IOException e) {
		}
		String str = null;
		if (status == 200) {
			try {
				str = new String(getmethod.getResponseBodyAsString().getBytes(
						"iso-8859-1"), "gb2312");
			} catch (UnsupportedEncodingException e) {
			} finally {
				getmethod.releaseConnection();
			}
		}
		return str;
	}
}
